/**
 * @file example_utils.h
 * @brief utils for convolution fprop 
 * @version 0.1
 * @date 2022-06-22
 *
 * @copyright Copyright (c) 2021
 *
 */
#ifndef EXAMPLE_CONV_FPROP_EXAMPLE_UTILS_H_  // NOLINT
#define EXAMPLE_CONV_FPROP_EXAMPLE_UTILS_H_  // NOLINT
#include <stdint.h>
#include <string.h>

#include "mcdnn/mcdnn.h"

const double kEps = 1e-5;

#define CHECK_CALL(f)                                                                              \
    {                                                                                              \
        mcdnnStatus_t err = static_cast<mcdnnStatus_t>(f);                                         \
        if (err != MCDNN_STATUS_SUCCESS) {                                                         \
            std::cout << "  Error occurred: " << err << std::endl;                                 \
            std::exit(1);                                                                          \
        }                                                                                          \
    }

void FwdConvCpu(float *dst,
                const float *src,
                const float *fil,
                uint32_t bs,
                uint32_t fu,
                uint32_t fv,
                uint32_t inx,
                uint32_t iny,
                uint32_t inc,
                uint32_t onx,
                uint32_t ony,
                uint32_t onc);

bool Check(const float *a, const float *b, uint32_t n, double eps = kEps, uint32_t skip = 0);

void PaddingCPU(float *dst,
                const float *src,
                const uint32_t dst_elements,
                int *pad,
                uint32_t h,
                uint32_t w,
                uint32_t batch,
                uint32_t in_channel);

void StripArgs(char *s);

bool FindArg(int argc, char *argv[], char *arg);
void DelArg(int argc, char **argv, int index);
int FindIntArg(int argc, char **argv, const char *arg, int def);
float FindFloatArg(int argc, char **argv, const char *arg, float def);

#endif  // NOLINT
